﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace XDLogonMonitor {
    class Process {
        private System.Diagnostics.Process[] allProcesses;

        private DateTime _StartTime;
        public DateTime StartTime { get { return _StartTime; } }

        public Process() { }

        public Boolean FindProcess(String runningProcess, String machineName) {
            try {
                allProcesses = System.Diagnostics.Process.GetProcessesByName(runningProcess,machineName);

                if (allProcesses.Length == 0) return false;

                foreach (System.Diagnostics.Process p in allProcesses) {
                    _StartTime = p.StartTime;
                    return true;
                }
            }
            catch (Exception e) {
                Console.Error.WriteLine(e.ToString());
                return false;
            }

            return false;
        }

        public Boolean FindProcess(String runningProcess ) {
            try {
                System.Diagnostics.Process[] test = System.Diagnostics.Process.GetProcesses();
                allProcesses = System.Diagnostics.Process.GetProcessesByName(runningProcess);

                if (allProcesses.Length == 0) return false;

                foreach (System.Diagnostics.Process p in allProcesses) {
                    _StartTime = p.StartTime;
                    return true;
                }
            }
            catch (Exception e) {
                Console.Error.WriteLine(e.ToString());
                return false;
            }

            return false;
        }
    }
}
